package org.example.crawler.domain;

import lombok.Builder;
import lombok.Data;
import lombok.experimental.Accessors;
import org.example.crawler.constant.RegexConstant;

import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @Author lyz
 * @Date 2025/3/27 14:52
 */
@Data
@Accessors(chain = true)
public class Flaw implements Serializable {

    private String flawNumber;

    private String publishTime;

    private String flawRiskLevel;

    private String refNumber;

    private String productName;

    private String remark;

    private String flawType;

    private String refLink;

    private String flawSoulution;

    private String patchInfo;

    private String checkInfo;

    private String submitTime;

    private String storageTime;

    private String updateTme;

    private String flawFile;


    public void setField(String name, String value) {
        if ("CNVD-ID".equals(name)) {
            this.flawNumber = value;
        }
        if ("公开日期".equals(name)) {
            this.publishTime = value;
        }
        if ("危害级别".equals(name)) {
            Pattern pattern = Pattern.compile(RegexConstant.chinese);
            Matcher matcher = pattern.matcher(value);
            if (matcher.find()) {
                value = matcher.group(0);
            }
            this.flawRiskLevel = value;
        }
        if ("影响产品".equals(name)) {
            this.productName = value;
        }
        if ("CVE ID".equals(name)) {
            this.refNumber = value;
        }
        if ("漏洞描述".equals(name)) {
            this.remark = value;
        }
        if ("漏洞类型".equals(name)) {
            this.flawType = value;
        }
        if ("参考链接".equals(name)) {
            this.refLink = value;
        }
        if ("漏洞解决方案".equals(name)) {
            this.flawSoulution = value;
        }
        if ("厂商补丁".equals(name)) {
            this.patchInfo = value;
        }
        if ("验证信息".equals(name)) {
            this.checkInfo = value;
        }
        if ("报送时间".equals(name)) {
            this.submitTime = value;
        }
        if ("收录时间".equals(name)) {
            this.storageTime = value;
        }
        if ("更新时间".equals(name)) {
            this.updateTme = value;
        }
        if ("漏洞附件".equals(name)) {
            this.flawFile = value;
        }
    }
}
